package com.musemun.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.musemun.common.CommonResult;
import com.musemun.pojo.Employee;
import com.musemun.pojo.EmployeeRepository;
import com.musemun.pojo.Permission;
import com.musemun.pojo.Vo.EmployeeHasRole;
import com.musemun.service.PermissionService;

import com.musemun.service.function.functionimpl.BaseEmployee;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/query_role")
public class QueryRoleController {

    @Resource
    PermissionService permissionService;

//    @PostMapping("/insert")
//    public Permission insertPermission(Permission permission){
//        permissionService.save(permission);
//        return permission;
//    }
    @Resource
    EmployeeRepository employeeRepository;
    @Resource
    BaseEmployee baseEmployee;

    @ApiOperation("查询登入用户的信息")
    @GetMapping("query")
    public CommonResult<EmployeeHasRole> returnEmployeeHasRole(){
        Employee employee = employeeRepository.findByUsername(SecurityContextHolder.getContext().getAuthentication().getName());
        return new CommonResult<>(200,"查询成功",baseEmployee.queryEmployeeHasRole(employee.getENo()));
    }

    @GetMapping("query_by_name/{name}")
    @ApiOperation("通过姓名查询用户信息")
    public CommonResult<EmployeeHasRole> returnEmployeeHasRoleByName(@PathVariable String name){
        Employee employee = baseEmployee.queryByNameEmployeeExist(name);
        return new CommonResult<>(200,"查询成功",baseEmployee.queryEmployeeHasRole(employee.getENo()));
    }
}
